public class Money {
    public static void main(String[] args) {
        Persion persion = new Persion();
        Thread thread = new Thread(persion);
        Thread thread1=new Thread(persion);
        thread.start();
        thread1.start();
    }
}
class Persion implements Runnable{
    private int money=10000;
    private boolean loop=true;

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
    public synchronized void Take(){
         if (money<1000){
            loop=false;
            return;
        }
        try {
            Thread.sleep(1000);
            money-=1000;
            System.out.println("取走了1000块"+Thread.currentThread().getName()+"剩余"+money);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void run() {
        while(loop){
            Take();
        }
    }
}